<template>
<view>






<view>


	<!-- 文章 -->
	<view class="detail-content" :style="'display:' + display">
		<!-- 标题 -->
		<view class="entry-title">{{detail.title}}</view>
		<!-- 文章互动数据 -->
		<view class="entry-data">
			<image src="/static/images/calendar.png"></image>
			<text>{{detailDate}}</text>

			<image src="/static/images/pageviews.png"></image>
			<text>{{detail.hits}}</text>

		</view>
		<!-- 文章正文 -->
		<view class="entry-summary" id="entry-summary">


			<jyf-parser :html="article_article"   :use-cache="true"	></jyf-parser>



		</view>






	</view>



	<view class="ditail-copyright" :style="'display:' + display">
		<block data-type="template" data-is="tempCopyright" data-attr="webSiteName:webSiteName,domain:domain">
<view> {{webSiteName}} </view>
</block>
	</view>



	<!-- 无法访问网络时 -->
	<view class="showerror" :style="'display:' + showerror">
		<!--image src="/static/images/cry80.png" style="height:100rpx;width:100rpx"></image-->
		<view class="errortext">{{errMessage}}</view>
	</view>

</view>
</view>
</template>

<script>

import config from "../../utils/config";
var Api = require("../../utils/api.js");
var util = require("../../utils/util.js");

var wxApi = require("../../utils/wxApi.js");
var wxRequest = require("../../utils/wxRequest.js");
const innerAudioContext = uni.createInnerAudioContext();
let isFocusing = false;
const pageCount = config.getPageCount;
var webSiteName = config.getWebsiteName;
var domain = config.getDomain;
var defaultskin = config.getskin;
let rewardedVideoAd = null;

export default {
  data() {
    return {
      detail: {
        content: {
          rendered: ""
        },
        title: {},
        acf: {}
      },
      content: {
        rendered: ""
      },
      title: {},
      acf: {},
      defaultskin: defaultskin,
      skin: defaultskin,
      title: '文章内容',
      webSiteName: webSiteName,
      html: " ",
      detailDate: '',
      display: 'none',
      showerror: 'none',
      page: 1,
      isLastPage: false,
      parentID: "0",
      scrollHeight: 0,
      xiangguan: [],
      link: '',
      dialog: {
        title: '',
        content: '',
        hidden: true
      },
      content: '',
      flag: 1,
	   tagStyle: {
	      img: "height:auto!important;display:block"
	    },
      enableComment: true,
      isLoading: false,
      total_comments: 0,
      userInfo: {},
      shareImagePath: '',
      fristOpen: false,
      domain: domain,
      platform: '',
      tagStyle: {},
      errMessage: "",
      commentCount: "",
      likeCount: "",
      postID: "",
      postImageUrl: "",
      commentsList: "",
      article_article: ""
    };
  },

  components: {},
  props: {},
  onShow: function (options) {
    var that = this;
    var skin = uni.getStorageSync('skin');

    if (skin != '') {
      that.setData({
        skin: skin
      });
    }
  },
  onLoad: function (options) {
    var self = this;
    self.fetchDetailData(options.id);
    var that = this;
    var skin = uni.getStorageSync('skin');

    if (skin != '') {
      that.setData({
        skin: skin
      });
    }
  },
  onUnload: function () {},
  onShareAppMessage: function (res) {
    return {
      title: this.detail.title,
      path: 'pages/detail/detail?id=' + this.detail.id,
      imageUrl: this.detail.post_full_image,
      success: function (res) {
        // 转发成功
        console.log(res);
      },
      fail: function (res) {
        console.log(res); // 转发失败
      }
    };
  },
  methods: {
    BackPage() {
      uni.navigateBack({
        delta: 1
      });
    },

    toHome() {
      uni.reLaunch({
        url: '/pages/index/index'
      });
    },

    gotowebpage: function () {
      var self = this;
      var url = '../webpage/webpage';
      uni.navigateTo({
        url: url + '?url=' + self.link
      });
    },
    copyLink: function (url) {
      uni.setClipboardData({
        data: url,
        success: function (res) {
          uni.getClipboardData({
            success: function (res) {
              uni.showToast({
                title: '链接已复制',
                image: "/static/images/uploads/link.png",
                duration: 2000
              });
            }
          });
        }
      });
    },
    copyText: function (e) {
      console.log(e);
      uni.setClipboardData({
        data: e.currentTarget.dataset.text,
        success: function (res) {
          uni.getClipboardData({
            success: function (res) {
              uni.showToast({
                title: '复制成功'
              });
            }
          });
        }
      });
    },
    gourl: function () {
      var url = '../webpage/webpage';
      uni.navigateTo({
        url: url + '?url=' + e.currentTarget.dataset.text
      });
    },
    goHome: function () {
      uni.switchTab({
        url: '../index/index'
      });
    },
    //获取是否开启评论设置
    getEnableComment: function (id) {
      var self = this;
      var getEnableCommentRequest = wxRequest.getRequest(Api.getEnableComment());
      getEnableCommentRequest.then(response => {
        if (response.data.enableComment != null && response.data.enableComment != '') {
          if (response.data.enableComment === "1") {
            self.setData({
              enableComment: true
            });
          } else {
            self.setData({
              enableComment: false
            });
          }
        }

        ;
      });
    },
    //获取文章内容
    fetchDetailData: function (id) {
      var self = this;
      var getPostDetailRequest = wxRequest.getRequest(Api.getShowUrl(id));
      var res;
      getPostDetailRequest.then(response => {
        res = response;
		console.log(res);
        if (response.data.data.code == 0 && response.data.data.status == "404") {
          self.setData({
            showerror: 'block',
            display: 'none',
            errMessage: response.data.message
          });
          return false;
        } // 设置页面标题：文章分类


        uni.setNavigationBarTitle({
          // title: res.data.title.rendered
          title: res.data.data.title
        });
        //WxParse.wxParse('article', 'html', response.data.content.rendered, self, 5)
        setTimeout(() => {
          self.article_article = response.data.data.content;
        }, 200);


        ;
        var _likeCount = response.data.like_count;
        self.setData({
          detail: response.data.data,
          likeCount: _likeCount,
          postID: id,
          link: response.data.data.link,
          detailDate: response.data.data.updatetime,
          display: 'block',
          total_comments: response.data.data.hits,
          postImageUrl: response.data.postImageUrl
        });
        return response.data;
      }).then(response => {
       
      }).catch(function (error) {
        console.log('error: ' + error);
      });
    },
    //拖动进度条事件
    //给a标签添加跳转和复制链接事件
    wxParseTagATap: function (e) {
      var self = this;
      var href = e.currentTarget.dataset.src;
      console.log(href);
      var domain = config.getDomain; //可以在这里进行一些路由处理

      if (href.indexOf(domain) == -1) {
        uni.setClipboardData({
          data: href,
          success: function (res) {
            uni.getClipboardData({
              success: function (res) {
                uni.showToast({
                  title: '链接已复制',
                  //icon: 'success',
                  image: "/static/images/uploads/link.png",
                  duration: 2000
                });
              }
            });
          }
        });
      } else {
        var slug = util.GetUrlFileName(href, domain);

        if (slug == 'index') {
          uni.switchTab({
            url: '../index/index'
          });
        } else {
          var getPostSlugRequest = wxRequest.getRequest(Api.getPostBySlug(slug));
          
        }
      }
    },
    //获取评论
    fetchCommentData: function () {
      
    }
  }
};
</script>
<style>
@import "./detail.css";
</style>